﻿<?php    
	include 'ChromePhp.php';
	require_once("class.phpmailer.php"); 
	set_time_limit(1500);
	 //参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名,文件名)
	$sendto_email='604267811@qq.com';
	//$sendto_email="1368473162@qq.com;604267811@qq.com;bin604267811@gmail.com;604267811@qq.com;362314321@qq.com;604267811@qq.com;2279445425@qq.com;604267811@qq.com;646998707@qq.com;604267811@qq.com";
	$maxAddressSize=2;//每次发送最大数量
    smtp_mail($sendto_email, '你好', '你好', NUll, "夏",null);    


	function smtp_mail( $sendto_email, $subject, $body, $extra_hdrs, $sender_name,$file_name){
		global $maxAddressSize;
		$mail = new PHPMailer();
		$error=null;
		//$mail->SMTPDebug  = 2; 
        $mail->IsSMTP();                  // send via SMTP    
		//使用QQ邮箱
        $mail->Host = "smtp.qq.com";   // SMTP servers    
        $mail->SMTPAuth = true;           // turn on SMTP authentication    
        $mail->Username = "604267811@qq.com";     // SMTP username  注意：普通邮件认证不需要加 @域名    
        $mail->Password = "bin86972793"; // SMTP password    
        $mail->From = "604267811@qq.com";      // 发件人邮箱   
        $mail->FromName = "=?utf-8?B?" . base64_encode("$sender_name") . "?=";  // 发件人ID
        $mail->CharSet = "UTF-8";   // 这里指定字符集！    
        $mail->Encoding = "base64";
		$name=base64_encode("新建文本文档.txt");
		echo $name;
		//$mail->AddAttachment( "新建文本文档.txt","新建文本文档.txt");//添加附件
		//邮件主题
        $mail->Subject ="=?utf-8?B?" . base64_encode("$subject") . "?="; 
        // 邮件内容    
        $mail->Body = $body;
		$address=explode(";",$sendto_email);//分割出所有地址
		$addressSize=count($address);//计算所有地址的数量
		if($addressSize>$maxAddressSize){
			$times=floor($addressSize/$maxAddressSize);
			for($i=0;$i<=$times-1;$i++){
				for($j=0;$j<$maxAddressSize;$j++){
					if (filter_var($address[$j+$i*$maxAddressSize], FILTER_VALIDATE_EMAIL)) {
						$mail->AddAddress($address[$j+$i*$maxAddressSize],null);
					}
				}
				if(!$mail->Send()){
						$error.=$mail->ErrorInfo;
					}else{
						$mail->ClearAddresses();
					}
			}
			if($times*$maxAddressSize<$addressSize){
				for($i=$times*$maxAddressSize;$i<$addressSize;$i++){
					if (filter_var($address[$i], FILTER_VALIDATE_EMAIL)) {
					$mail->AddAddress($address[$i],null);
					}			
				}
				if(!$mail->Send()){
					$error.=$mail->ErrorInfo.'2';
				}
			}
			
			if($error!=null){
				echo $error;
			}else{
				echo 1;
			}
		}else{
			for($j=0;$j<$addressSize;$j++){
				if (filter_var($address[$j], FILTER_VALIDATE_EMAIL)) {
					$mail->AddAddress($address[$j],null);
				}
			}		
			if(!$mail->Send())    
			{    
				echo $mail->ErrorInfo;
				exit;    
			}    
			else {    
				echo 1;    
			}    
		}    
   }
	
?>  
